﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using BUS;
using DTO;
namespace DuanGiuaKy
{
    public partial class ctrlU_adm_qlMonHoc : UserControl
    {
        public ctrlU_adm_qlMonHoc()
        {
            InitializeComponent();
        }

        private void ctrlU_adm_qlMonHoc_Load(object sender, EventArgs e)
        {
           dgvMonHoc.DataSource= BUS.MONHOC_BUS.loadDSMonHoc();
        }

        private void tsbtnXoa_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Bạn có chắc muốn xóa?", "Cảnh báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (res == DialogResult.OK)
            {
                string mamh = dgvMonHoc.CurrentRow.Cells[0].Value.ToString();
                MONHOC_BUS.xoaMH(mamh);
                dgvMonHoc.DataSource = MONHOC_BUS.loadDSMonHoc();
            }
        }
        private void tsbtnThem_Click(object sender, EventArgs e)
        {

            frm_adm_qlMonHoc qlmh = new frm_adm_qlMonHoc();
            qlmh.ShowDialog();
            dgvMonHoc.DataSource = MONHOC_BUS.loadDSMonHoc();
        }

        private void tsbtnSua_Click(object sender, EventArgs e)
        {
            try
            {
                int rInd = dgvMonHoc.CurrentCell.RowIndex;
                string maph = dgvMonHoc.Rows[rInd].Cells[0].Value.ToString();
                string tenmh = dgvMonHoc.Rows[rInd].Cells[1].Value.ToString();
                string loaimon = dgvMonHoc.Rows[rInd].Cells[3].Value.ToString();
                string sotc = dgvMonHoc.Rows[rInd].Cells[2].Value.ToString();
                string mota = dgvMonHoc.Rows[rInd].Cells[4].Value.ToString();
                frm_adm_qlMonHoc qlmh = new frm_adm_qlMonHoc(maph, tenmh, sotc, loaimon, mota);
                qlmh.ShowDialog();
                dgvMonHoc.DataSource = MONHOC_BUS.loadDSMonHoc();
            }
            catch (System.NullReferenceException)
            {
                if (dgvMonHoc.SelectedRows.Count == 0)
                    MessageBox.Show("Chọn 1 môn học để chỉnh sửa", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

    }
}
